package com.woniuxy.redis.lock.configuration;

/**
 * description: RabbitmqConfiguration <br>
 * date: 2022/1/13 10:15 下午 <br>
 * author: shesaifei <br>
 * version: 1.0 <br>
 */

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * rabbitmq配置类
 */
@Configuration
public class RabbitmqConfiguration {

    //消息转换器，主要针对发送对象

    @Bean
    public MessageConverter messageConverter() {
        return new Jackson2JsonMessageConverter();
    }
    //定义交换机

    @Bean
    public TopicExchange exchangeadd() {
        return new TopicExchange("exchangeadd");
    }
    //定义队列

    @Bean
    public Queue queueadd() {
        return new Queue("queueadd");
    }

    //将队列和交换机还有路由绑定

    @Bean
    public Binding bindingqueueadd(Queue queueadd, TopicExchange exchangeadd) {
        return BindingBuilder.bind(queueadd).to(exchangeadd).with("#.add.#");
    }
}
